package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Exercise;

@Repository(value="exerciseDao")
public class ExerciseDaoImpl implements ExerciseDao {

	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<Exercise> list(Exercise exercise) {

		List<Exercise> list = null;

		try {
			list = sqlSessionTemplate.selectList("exerciselist",exercise);
		} catch (Exception e) {

			e.printStackTrace();
		}

		return list;
	}

	public int add(Exercise exercise) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("exerciseadd",exercise);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public Exercise view(long exerciseNo) {
		Exercise exercise = new Exercise();

		try {
			exercise = sqlSessionTemplate.selectOne("exerciseview", exerciseNo);
		} catch (Exception e) {
			
			e.printStackTrace();
		}

		return exercise;
	}

	public int modify(Exercise exercise) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("exercisemodify",exercise);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(long exerciseNo) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("exerciseremove",exerciseNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public List<Exercise> exercisePurposeSelectList(Exercise exercise) {
		List<Exercise>list = null;

		try {
			list = sqlSessionTemplate.selectList("exercisePurposeSelectList",exercise);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	
	
////////////////////////////////////////////////////////////////////////////////////////////////////	
/////////////////////////////admin 운동 조회 테스트
	
	public List<Exercise> adminList() {
		
		List<Exercise> adminList = null;
		
		try {
			adminList = sqlSessionTemplate.selectList("adminexerciseList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return adminList;
	}
	
	
}
